package com.example.broadcast;

import androidx.appcompat.app.AppCompatActivity;

import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    private MyReceiver receiver;
    private Button btn;
    private EditText etNum;
    private SharedPreferences sp;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = findViewById(R.id.btn);
        etNum = findViewById(R.id.et_number);

        sp = getSharedPreferences("config",MODE_PRIVATE);

//        //实例化广播接受者
//        receiver = new MyReceiver();
//        String action = "android.providerTelephony.SMS.RECEIVED";
//        IntentFilter filter = new IntentFilter(action);
//        registerReceiver(receiver,filter);
    }

//    @Override
//    protected void onDestroy() {
//        super.onDestroy();
//        unregisterReceiver(receiver);
//    }

    public void click(View view){
        String number = etNum.getText().toString().trim();
        SharedPreferences.Editor editor = sp.edit();
                editor.putString("number",number);
                editor.commit();
        Toast.makeText(this,"保存成功",Toast.LENGTH_LONG).show();

    }
}
